//
//  MedicalRecordCellViewModel.swift
//  EyeVisionForPatients
//
//  Created by PMC on 2021/8/19.
//  Copyright © 2021 QDSG. All rights reserved.
//

import UIKit

class MedicalRecordCellViewModel: NSObject {
    let section: MedicalRecordSection
    
    init(with section: MedicalRecordSection) {
        self.section = section
    }
    
    var mode: MedicalRecordSectionMode { section.mode }
    
    var departmentName: String { "科室：\(section.model.dept ?? "")" }
    var cardNo: String { "就诊卡号：\(section.model.card ?? "")" }
    var time: String { "就诊时间：\(section.model.diagDate ?? "")" }
    
    var patientName: String { "就诊人：\(section.model.name ?? "")" }
    var patientSex: String { "性别：\(section.model.sex ?? "")" }
    var patientAge: String { "年龄：\(section.model.age ?? "")" }
    
    var desc: String? {
        switch mode {
        case .mainState:        return section.model.medhisZs
        case .illnessHistory:   return section.model.medhisXbs
        case .pastHistory:      return section.model.medhisJws
        case .specialCheck:     return section.model.eyeSpecial
        case .diagnose:         return section.model.diagNames
        case .opinion:          return section.model.diagnoseAdvice
        default:                return nil
        }
    }
    
    /// 签名
    var sign: String { section.model.sign ?? "" }
    
    var imageUrls: [String] { section.model.urlList ?? [] }
    
    var itemCount: Int { imageUrls.count }
    
    var itemWH: CGFloat {
        let wh = (screenW - 16 * 2 - 15 * 3) / 4
        return wh
    }
    
    var collectionViewHeight: CGFloat {
        guard itemCount > 0 else { return 0.0 }
        
        let col = 4
        let row = (itemCount - 1) / col + 1
        
        return itemWH * CGFloat(row) + 15.0 * CGFloat(row - 1)
    }
}
